from django.http.response import HttpResponseRedirect
from django.shortcuts import render
from rest_framework.renderers import TemplateHTMLRenderer
from rest_framework.response import Response
from django.conf import settings

from rest_framework.views import APIView

# Create your views here.

class LoginView(APIView):

  renderer_classes = [TemplateHTMLRenderer]

  def get_success_url(self, user):
    url = settings.LOGIN_REDIRECT_URL if user.user_type == 'A' or user.user_type == 'E'  else settings.TEA_LOGIN_REDIRECT_URL if user.user_type == 'T' else settings.STU_LOGIN_REDIRECT_URL
    return url

  def get(self, request, *args, **kwargs):
    if self.request.user.is_authenticated == True:
      return HttpResponseRedirect(self.get_success_url(self.request.user))
  
    return Response({
      'stu_login_url': settings.STUDENT_LOGIN_PAGE
    }, template_name='registration/mobile-login.html')